package com.maikec.utils.mybatis.base;

import com.maikec.utils.mybatis.provider.DeleteProvider;
import com.maikec.utils.mybatis.provider.InsertProvider;
import com.maikec.utils.mybatis.provider.SelectProvider;
import com.maikec.utils.mybatis.provider.UpdateProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @description 通用Mapper
 * @author maikec
 * @date 2018/7/12
 */
@Mapper
public interface BaseMapper<T>{
    /**
     * 新增
     * @param t pojo
     * @return int insert成功的总行数
     */
    @org.apache.ibatis.annotations.InsertProvider(type = InsertProvider.class, method = "insert")
    int insert(T t);

    /**
     * 根据id更新
     * @param t pojo
     * @return int 返回1更新成功、0失败
     */
    @org.apache.ibatis.annotations.UpdateProvider(type = UpdateProvider.class, method = "update")
    int updateById(T t);

    /**
     * 根据id删除
     * @param t pojo
     * @return int delete成功的总行数
     */
    @org.apache.ibatis.annotations.DeleteProvider(type= DeleteProvider.class, method = "delete")
    int deleteById(T t);

    /**
     * 根据id查询
     * @param t pojo
     * @return T 返回t
     */
    @org.apache.ibatis.annotations.SelectProvider(type= SelectProvider.class, method = "selectById")
    T selectById(T t);

    /**
     * 根据给定的pojo查询列表
     * @param t
     * @return
     */
    @org.apache.ibatis.annotations.SelectProvider(type= SelectProvider.class, method = "select")
    List<T> select(T t);

    /**
     * 根据分页
     * @param t
     * @param pageNum 页签
     * @param pageSize 页码
     * @return
     */
    @org.apache.ibatis.annotations.SelectProvider(type= SelectProvider.class, method = "selectPage")
    List<T> selectPage(@Param("t") T t, @Param("pageNumKey") int pageNum,
                             @Param("pageSizeKey") int pageSize);
}
